import request from '@/utils/request'

//  专业分页
export function getMajorList(params) {
  return request({
    url: '/base/major/listPage',
    method: 'get',
    params
  })
}

// 更新专业
export function updateMajorField(params) {
  return request({
    url: '/base/major/updateById',
    method: 'put',
    data: params
  })
}

// 批量删除 逗号隔开的id字符串
export function bathDeleteMajor(ids) {
  return request({
    url: `/base/major/deleteByIds/${ids}`,
    method: 'delete'
  })
}

// 新增专业
export function addMajor(data) {
  return request({
    url: `/base/major/add`,
    method: 'put',
    data
  })
}

export function getMajorClassCodeList(majorSubjectCode) {
  return request({
    url: `/base/major/getMajorClassCodeList?majorSubjectCode=${majorSubjectCode}`,
    method: 'get'
  }).then(res => {
    if (res.status) {
      return res.data.map(d => ({
        name: d.majorClass,
        value: d.majorClassCode
      }))
    } else {
      return []
    }
  })
}

// 通过门类代码,专业类代码获取专业国标库信息
export function getStandardCodeList(majorSubjectCode, majorClassCode) {
  return request({
    url: `/base/major/getStandardCodeList`,
    method: 'get',
    params: {
      majorSubjectCode,
      majorClassCode
    }
  }).then(res => {
    if (res.status) {
      return res.data.map(d => ({
        name: d.standardName,
        value: d.standardCode
      }))
    } else {
      return []
    }
  })
}

// 检查专业代码是否重复
export function checkCodeRepeat(majorCode) {
  return request({
    url: `/base/major/checkCodeRepeat?majorCode=${majorCode}`,
    method: 'get'
  })
}

// 生成专业代码
export function createMajorCode(collegeCode) {
  return request({
    url: `/base/major/createMajorCode?collegeCode=${collegeCode}`,
    method: 'get'
  })
}

// 根据培养层次获取专业门类
export function getClassMajorByEduLevel(eduLevelCode) {
  return request({
    url: `/base/majorSubject/getClassMajorByEduLevel?eduLevelCode=${eduLevelCode}`,
    method: 'get'
  }).then(res => {
    if (res.status) {
      return res.data.map(d => {
        return {
          name: d.majorSubject,
          value: d.majorSubjectCode
        }
      })
    } else {
      return []
    }
  })
}

// 通过专业门类 获取专业类
export function getMajorClassBySubject(majorSubjectCode) {
  return request({
    url: `/base/majorClass/getMajorClassBySubject?majorSubjectCode=${majorSubjectCode}`,
    method: 'get'
  }).then(res => {
    if (res.status) {
      return res.data.map(d => {
        return {
          name: d.majorClass,
          value: d.majorClassCode
        }
      })
    } else {
      return []
    }
  })
}

